package thread_pool;


/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/5/25
 * Time:18:56
 * 线程--内存溢出
 **/
public class PoolDemo35 {

    static class OOMObject {

        private byte[] bytes = new byte[1*1024*1024];//1M大小的对象
    }

    static ThreadLocal<OOMObject> threadLocal = new ThreadLocal<>();

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 5; i++) {
            int finalI = i;
            Thread t1 = new Thread(new Runnable() {
                @Override
                public void run() {
                    OOMObject oomObject = new OOMObject();
                    //set threadLocal
                    System.out.println("任务"+finalI+"执行了");
                    threadLocal.set(oomObject);
                    //不用对象了
                    oomObject = null;
                }
            });
            t1.start();

            //等待
            Thread.sleep(200);
        }
    }
}
